import Vue from 'vue';
import App from './App.vue';
import router from './router';
import axios from 'axios';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.config.productionTip = false;

Vue.use(ElementUI);

// 设置 Axios 的默认基地址
axios.defaults.baseURL = 'http://127.0.0.1:8100';
// axios.defaults.baseURL = 'http://121.40.20.233:8100';

Vue.prototype.$http = axios;

// 添加一个请求拦截器
axios.interceptors.request.use(config => {
  // 从localStorage中获取用户名
  const username = localStorage.getItem('username');
  if (username) {
    config.headers.username = username;
  }
  return config;
}, error => {
  return Promise.reject(error);
});

new Vue({
  router,
  render: h => h(App)
}).$mount('#app');
